<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/06/23
  Time: 17:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加车位租赁信息</title>
</head>
<body>

<form action="AddServlet" method="get">
    <table border="1" cellspacing="0">
        <tr>
            <th colspan="2" style="font-size: 30px">添加车位租赁信息</th>
        </tr>
        <tr>
            <td>租赁人姓名(*)</td>
            <td><input type="text" class="userName" name="userName"></td>
        </tr>
        <tr>
            <td>车牌号(*)</td>
            <td><input type="text" class="carNum" name="carNum"><span></span></td>
        </tr>
        <tr>
            <td>到期日期(*)</td>
            <td><input type="text" class="maturityDate" name="maturityDate"></td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <button>提交</button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" onclick="history.back()">返回</button>
            </td>
        </tr>
    </table>
</form>

<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(function () {
        var verification = false;
        $(".carNum").blur(function () {
            var carNum = $(".carNum").val();
            $.get("CheckServlet", {"carNum": carNum}, function (data) {
                if (data > 0) {
                    $("span").html("<br/>该车辆已有车位!");
                    verification = true;
                } else {
                    $("span").html("");
                    verification = false;
                }
            });
        });

        $("form").submit(function () {
            var isSub = true;
            var isFocus = false;
            $("input[type='text']").each(function () {
                if ($(this).val() === "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            $("select").each(function () {
                if ($(this).val() === "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            $("textarea").each(function () {
                if ($(this).val() === "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            if (!isSub) {
                alert("此输入框不能为空!");
                return false;
            }

            var dataFormat = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
            var flag = dataFormat.test($(".maturityDate").val());
            if (!flag) {
                alert("日期格式错误，请重新输入!");
                $(".createDate").focus();
                return false;
            }

            if (verification) {
                return false;
            }

        });

    })

</script>
</body>
</html>
